package cn.kgc.crowdfundingadminspringboot2.service;

import cn.kgc.crowdfundingadminspringboot2.mapper.CertMapper;
import cn.kgc.crowdfundingadminspringboot2.pojo.Cert;
import cn.kgc.crowdfundingadminspringboot2.pojo.CertExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CertServiceimpl implements  CertService{
    @Resource
    CertMapper certMapper;
    @Override
    public PageInfo<Cert> queryForkeywordPage(Integer pageNum, Integer PageSize, String keyword) {
        PageHelper.startPage(pageNum,PageSize);
        CertExample example=new CertExample();
        CertExample.Criteria criteria=example.createCriteria();
        criteria.andNameLike("%"+keyword+"%");
        List<Cert> certs = certMapper.selectByExample(example);
        PageInfo info=new PageInfo(certs);
        return info;
    }

    @Override
    public List<Cert> getRoleListByIdList(List<Integer> certIdList) {
        CertExample example=new CertExample();
        CertExample.Criteria criteria=example.createCriteria();
        criteria.andIdIn(certIdList);
        return certMapper.selectByExample(example);
    }

    @Override
    public void saveCert(String certName) {
        certMapper.insert(new Cert(null,certName));

    }

    @Override
    public void batchRemove(List<Integer> certIdList) {
        CertExample example=new CertExample();
        CertExample.Criteria criteria=example.createCriteria().andIdIn(certIdList);
        certMapper.deleteByExample(example);
    }

    @Override
    public void updateRole(Cert cert) {
        certMapper.updateByPrimaryKey(cert);
    }

}
